package g;

import com.pgl.sys.ces.out.ISdkLite;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.RandomAccess;

/* compiled from: Options */
public final class s extends AbstractList<h> implements RandomAccess {
    public final h[] a;
    public final int[] b;

    public s(h[] hVarArr, int[] iArr) {
        this.a = hVarArr;
        this.b = iArr;
    }

    public static void b(long j, e eVar, int i, List<h> list, int i2, int i3, List<Integer> list2) {
        e eVar2 = eVar;
        int i4 = i;
        List<h> list3 = list;
        int i5 = i2;
        int i6 = i3;
        List<Integer> list4 = list2;
        if (i5 < i6) {
            int i7;
            int i8;
            int i9 = i5;
            while (i9 < i6) {
                if (((h) list3.get(i9)).p() >= i4) {
                    i9++;
                } else {
                    throw new AssertionError();
                }
            }
            h hVar = (h) list.get(i2);
            h hVar2 = (h) list3.get(i6 - 1);
            if (i4 == hVar.p()) {
                i9 = ((Integer) list4.get(i5)).intValue();
                i5++;
                i7 = i5;
                i8 = i9;
                hVar = (h) list3.get(i5);
            } else {
                i8 = -1;
                i7 = i5;
            }
            long j2 = 4;
            e eVar3;
            int i10;
            int i11;
            if (hVar.j(i4) != hVar2.j(i4)) {
                e eVar4;
                i9 = 1;
                for (i5 = i7 + 1; i5 < i6; i5++) {
                    if (((h) list3.get(i5 - 1)).j(i4) != ((h) list3.get(i5)).j(i4)) {
                        i9++;
                    }
                }
                long j3 = ((j + ((long) ((int) (eVar2.b / 4)))) + 2) + ((long) (i9 * 2));
                eVar2.E0(i9);
                eVar2.E0(i8);
                i5 = i7;
                while (i5 < i6) {
                    byte j4 = ((h) list3.get(i5)).j(i4);
                    if (i5 == i7 || j4 != ((h) list3.get(i5 - 1)).j(i4)) {
                        eVar2.E0(j4 & ISdkLite.REGION_UNSET);
                    }
                    i5++;
                }
                eVar3 = new e();
                i10 = i7;
                while (i10 < i6) {
                    int i12;
                    int i13;
                    byte j5 = ((h) list3.get(i10)).j(i4);
                    i9 = i10 + 1;
                    for (i11 = i9; i11 < i6; i11++) {
                        if (j5 != ((h) list3.get(i11)).j(i4)) {
                            i12 = i11;
                            break;
                        }
                    }
                    i12 = i6;
                    if (i9 == i12 && i4 + 1 == ((h) list3.get(i10)).p()) {
                        eVar2.E0(((Integer) list4.get(i10)).intValue());
                        i13 = i12;
                        eVar4 = eVar3;
                    } else {
                        eVar2.E0((int) ((((long) ((int) (eVar3.b / j2))) + j3) * -1));
                        i13 = i12;
                        eVar4 = eVar3;
                        b(j3, eVar3, i4 + 1, list, i10, i12, list2);
                    }
                    eVar3 = eVar4;
                    i10 = i13;
                    j2 = 4;
                }
                eVar4 = eVar3;
                eVar2.E(eVar4, eVar4.b);
                return;
            }
            i5 = 0;
            i10 = Math.min(hVar.p(), hVar2.p());
            int i14 = i4;
            while (i14 < i10 && hVar.j(i14) == hVar2.j(i14)) {
                i5++;
                i14++;
            }
            long j6 = 1 + (((j + ((long) ((int) (eVar2.b / 4)))) + 2) + ((long) i5));
            eVar2.E0(-i5);
            eVar2.E0(i8);
            i11 = i4;
            while (true) {
                i8 = i4 + i5;
                if (i11 >= i8) {
                    break;
                }
                eVar2.E0(hVar.j(i11) & ISdkLite.REGION_UNSET);
                i11++;
            }
            if (i7 + 1 != i6) {
                eVar3 = new e();
                eVar2.E0((int) ((((long) ((int) (eVar3.b / 4))) + j6) * -1));
                b(j6, eVar3, i8, list, i7, i3, list2);
                eVar2.E(eVar3, eVar3.b);
                return;
            } else if (i8 == ((h) list3.get(i7)).p()) {
                eVar2.E0(((Integer) list4.get(i7)).intValue());
                return;
            } else {
                throw new AssertionError();
            }
        }
        throw new AssertionError();
    }

    public static s c(h... hVarArr) {
        int i = 0;
        if (hVarArr.length == 0) {
            return new s(new h[0], new int[]{0, -1});
        }
        int i2;
        ArrayList arrayList = new ArrayList(Arrays.asList(hVarArr));
        Collections.sort(arrayList);
        ArrayList arrayList2 = new ArrayList();
        for (i2 = 0; i2 < arrayList.size(); i2++) {
            arrayList2.add(Integer.valueOf(-1));
        }
        for (i2 = 0; i2 < arrayList.size(); i2++) {
            arrayList2.set(Collections.binarySearch(arrayList, hVarArr[i2]), Integer.valueOf(i2));
        }
        if (((h) arrayList.get(0)).p() != 0) {
            int i3;
            i2 = 0;
            while (i2 < arrayList.size()) {
                h hVar = (h) arrayList.get(i2);
                i3 = i2 + 1;
                int i4 = i3;
                while (i4 < arrayList.size()) {
                    h hVar2 = (h) arrayList.get(i4);
                    Objects.requireNonNull(hVar2);
                    if (!hVar2.n(0, hVar, 0, hVar.p())) {
                        continue;
                        break;
                    } else if (hVar2.p() == hVar.p()) {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append("duplicate option: ");
                        stringBuilder.append(hVar2);
                        throw new IllegalArgumentException(stringBuilder.toString());
                    } else if (((Integer) arrayList2.get(i4)).intValue() > ((Integer) arrayList2.get(i2)).intValue()) {
                        arrayList.remove(i4);
                        arrayList2.remove(i4);
                    } else {
                        i4++;
                    }
                }
                i2 = i3;
            }
            e eVar = new e();
            b(0, eVar, 0, arrayList, 0, arrayList.size(), arrayList2);
            i3 = (int) (eVar.b / 4);
            int[] iArr = new int[i3];
            while (i < i3) {
                iArr[i] = eVar.J();
                i++;
            }
            if (eVar.Q()) {
                return new s((h[]) hVarArr.clone(), iArr);
            }
            throw new AssertionError();
        }
        throw new IllegalArgumentException("the empty byte string is not a supported option");
    }

    public Object get(int i) {
        return this.a[i];
    }

    public final int size() {
        return this.a.length;
    }
}
